(function() {
	Wallet.widget.StatisticDataTable = function(el, config) {
		Wallet.widget.StatisticDataTable.superclass.constructor.call(this, el, config);	
	}
	
	var Lang = YAHOO.lang,
		DataTable = YAHOO.widget.DataTable,
		DataSource = YAHOO.util.DataSource,
		Dom = YAHOO.util.Dom,
		HtmlDataTable = Wallet.widget.HtmlDataTable,
		StatisticDataTable = Wallet.widget.StatisticDataTable,
		AccountRecordPanel = Wallet.widget.AccountRecordPanel;
	
	Lang.extend(StatisticDataTable, HtmlDataTable, {
		columnDefs: [{
			key: "date", 
			formatter: /*Money.formatDateButton*/YAHOO.widget.DataTable.formatDate, 
			sortable: true, 
			resizeable: true, 
			label: "Date"
		}, {
			key: "income", 
//			formatter: Money.formatGreenColorText, 
			sortable: true, 
			resizeable: true, 
			label: "Income"
		}, {
			key: "expend", 
//			formatter: Money.formatRedColorText, 
			sortable: true, 
			resizeable: true, 
			label: "Expend"
		}, {
			key: "total", 
//			formatter: Money.formatColorText, 
			sortable: true, 
			resizeable: true, 
			label: "Total"
		}],
		responseType: YAHOO.util.DataSource.TYPE_HTMLTABLE,
		responseSchema: {   
			fields: [{
				key: "date"/*, parser: YAHOO.util.DataSource.parseDate*/
			}, {
				key: "income"
			}, {
				key: "expend", 
				parser: YAHOO.util.DataSource.parseNumber
			}, {
				key: "total"
			}]   
		},
		onEventSelectRow: function(args) {		
			StatisticDataTable.superclass.onEventSelectRow.call(this, args);
				
			var row = args.target;
			var record = this.getRecord(row);
			var date = record.getData("date");
			
			if (!this.accountRecordPanel) {
				var month = date.substr(0, 7);
				var panel = new AccountRecordPanel("div-detail-" + month, {
					width: "600px",
					dataUri: "account.php?date="
				});	
				panel.render();	
				
				this.accountRecordPanel = panel;
				
				Wallet.widget.OverlayManager.register(this.accountRecordPanel);
			}
			
			this.accountRecordPanel.load(date);
			
			this.accountRecordPanel.show();
			Wallet.widget.OverlayManager.bringToTop(this.accountRecordPanel);			
		}
	});
}());